const crypto = require('crypto');
module.exports = app => {
  app.infos = {
    appID: 'wxacb30470e1978dd6',
    appSecret: 'fc1f8bbf7b78182d90a61269c9ec721f',
    payAppId: 'wxf9ac4292cbeb4ab5',
    payAppSecret: '20a80863d7733cab39360b95893d20b4'
  }
  app.webcount = 0;
  // app.beforeStart(async () => {

  // })
  app.encode = function (text, key) {
    var secret = key || "asdhjwheru*asd123&123";
    var cipher = crypto.createCipher('aes-256-cbc', secret);
    var crypted = cipher.update(text, 'utf8', 'hex');
    crypted += cipher.final('hex');
    console.log(crypted);
    return crypted;
  }
  app.decode = function (text, key) {
    var secret = key || "asdhjwheru*asd123&123";
    var decipher = crypto.createDecipher('aes-256-cbc', secret);
    var dec = decipher.update(text, 'hex', 'utf8');
    dec += decipher.final('utf8');//解密之后的值  
    console.log(dec);
    return dec;
  }

  app.logger.debug('debug info');
};
